isConnected=[[1,1,0],[1,1,0],[0,0,1]]
def dfs(isConnected,i,j):
    isConnected[j][j]=0
    isConnected[i][j]=0
    isConnected[j][i]=0
    for k in range(len(isConnected[j])):
        if isConnected[j][k]==1:
            dfs(isConnected,j,k)
def findCircleNum(isConnected):
    province_count=0
    #寻找省份
    for i in range(len(isConnected)):
        #外循环用来扫描行
        for j in range(len(isConnected[0])):
            #内循环用来扫描列
            if i==j and isConnected[i][j]==1:
                #此城市为一个省的遍历开始点或者是单独的一个省
                #将该点归为0
                isConnected[i][j]=0
                #省份数加1
                province_count+=1
            if i!=j and isConnected[i][j]==1:
                #1.不是自身的那个值  2.和其他城市相邻
                dfs(isConnected,i,j)
    return province_count
print(findCircleNum(isConnected))
